package org.bb.spring_security_002.tacos.security;

import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;

import javax.sql.DataSource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Autowired
    DataSource dataSource;

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        // super.configure(auth);
        auth
            .inMemoryAuthentication()
                .passwordEncoder(NoOpPasswordEncoder.getInstance())
                .withUser("buzz")
                    .password("infinity")
                    .authorities("ROLE_USER")
                .and()
                .withUser("woody")
                    .password("bullseye")
                    .authorities("ROLE_USER");
    }

    public static void main(String[] args) {
        List<Item> dataList = new ArrayList<>();
        dataList.add(new Item("33.3", "1/3"));
        dataList.add(new Item("28.6", "1/3.5"));
        dataList.add(new Item("22.2", "1/4.5"));
        dataList.add(new Item("18.2", "1/5.5"));
        dataList.add(new Item("16.7", "1/6"));
        dataList.add(new Item("15.4", "1/6.5"));
        dataList.add(new Item("14.3", "1/7"));
        dataList.add(new Item("13.3", "1/7.5"));
        dataList.add(new Item("12.5", "1/8"));
        dataList.add(new Item("11.8", "1/8.5"));
        dataList.add(new Item("11.1", "1/9"));
        dataList.add(new Item("9.1", "1/11"));
        dataList.add(new Item("8.3", "1/12"));
        dataList.add(new Item("7.7", "1/13"));
        dataList.add(new Item("7.1", "1/14"));
        dataList.add(new Item("6.7", "1/15"));
        dataList.add(new Item("6.25", "1/16"));
        dataList.add(new Item("5.9", "1/17"));
        dataList.add(new Item("5.6", "1/18"));
        dataList.add(new Item("5.3", "1/19"));
        Collections.shuffle(dataList);
        for (Item item : dataList) {
            System.out.print(item.getParam1() + "    ");
        }
    }

    @Data
    public static class Item {
        private String param1;
        private String param2;

        public Item(String param1, String param2) {
            this.param1 = param1;
            this.param2 = param2;
        }
    }
}
